#!/usr/bin/python
# -*- coding: utf-8 -*-
n1=input()
n2=input()
n=n2-n1

if n<0 and n<-180:
    print(n + 360)
elif n>0 and n>180:
    print(n - 360)
else:
    print n